#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <signal.h>

#define SOFTAP_PORT             8082
#define SOFTAP_IP               "192.168.1.121"

#define WLAN_SSID_MAX_LEN       32
#define WLAN_PASSWD_MAX_LEN     63

#define TEST_SSID   "linux"
#define TEST_PASSWD "19000101"

int socket_fd = -1;

typedef struct{
    unsigned char ssid[WLAN_SSID_MAX_LEN];
    unsigned char pwd[WLAN_PASSWD_MAX_LEN];
    unsigned char ssid_len;
    unsigned char pwd_len;
    unsigned char random;
}WIFI_INFO;


int main(void)
{
    int ret = 0;
    fd_set rset;
    char *data = "SSID=hklt2020&PSK=12345678";
    int data_len = strlen(data);
    char recv_data[1024] = {0};


    socket_fd = socket(PF_INET,  SOCK_STREAM, 0); //创建套接字文件, 指定TCP协议
    if(socket_fd == -1)
    {
        printf("socket fail\n");
        return -1;
    }
    struct sockaddr_in softap_addr = {0};
    softap_addr.sin_family = AF_INET;
    softap_addr.sin_port = htons(SOFTAP_PORT);
    softap_addr.sin_addr.s_addr = inet_addr(SOFTAP_IP);

    ret = connect(socket_fd, (struct sockaddr *)&softap_addr, sizeof(softap_addr));
    if(ret == -1)
    {
        printf("connect fail\n");
        return -1;
    }

    FD_ZERO(&rset);
    
    while(1)
    {
        ret = send(socket_fd, (void *)data, data_len, 0);
        if(ret == -1)
        {
            printf("send fail.\n");
            return -1;
        }
        ret = recv(socket_fd, recv_data, 1024, 0);
        if(ret > 0)
        {
            printf("client recv: %s\n", recv_data);
        }
        sleep(1);


    }



    
}